package models.bill;

import models.UUIDModel;
import models.constants.DeletedStatus;
import models.enums.FeeType;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.util.List;

/**
 * 账单明细
 * TODO  物业费、房租 针对的是  合同
 *       工单        针对的是  房间
 * 建议 通过 ChargeItem 中转解决
 *
 */
@Entity
@Table(name = "bl_bill_details")
public class BillDetail extends UUIDModel {

    /**
     * 所属账单
     */
    @JoinColumn(name = "bill_id")
    @ManyToOne
    public Bill bill;

    /**
     * 摘要.
     */
    @Column(name = "remark", length = 100)
    public String remark;

    /**
     * 费用类型
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "fee_type", length = 15)
    public FeeType feeType;

    /**
     * 账单金额
     */
    @Column(name = "amount")
    public BigDecimal amount;

    /**
     * 根据账单,查询账单明细
     * @param billId
     * @return
     */
    public static List<BillDetail>  loadByBillId(String billId){
        return BillDetail.find("bill.id = ? and deleted = ?" , billId , DeletedStatus.UN_DELETED).fetch();
    }

    /**
     *
     * @param id
     * @return
     */
    public static BillDetail findByDetailId(long id){
        return BillDetail.find("id = ? and deleted = ?" ,id, DeletedStatus.UN_DELETED).first();
    }

}
